home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 27 (1992-03)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip / MegaDisc 27 (1992-03)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf / AMOS / palet.ASC < prev    next >
Text File  |  1992-03-30  |  14KB  |  430 lines

  1. '================================================================
  2. '                 P A L E T T E   S E T T E R  
  3. '
  4. '             John Collett, Hamilton, New Zealand  
  5. '
  6. '                        February 1992 
  7. '
  8. '      Copy any pieces from this which you may find useful,    
  9. '      but please leave this program intact, as it stands. 
  10. '
  11. '================================================================
  12. Screen Open 1,640,260,16,Hires
  13. Curs Off : Flash Off : Palette $0,$79A,$FFF,$FB5
  14. '====== Demo : Introduction, organisation, explanations =========
  15. HEADER
  16. LUPE[3,640,Hires]
  17. EX4
  18. LUPE[4,320,Lowres]
  19. Edit 
  20. '==============  Procedures used by Demo   ======================  
  21. Procedure HEADER
  22.    SH[100,30,"AMOS PALETTE SETTER DEMONSTRATION",3]
  23.    SH[50,50,"This demo will show a Palette Setter in each of seven",2]
  24.    SH[50,60,"different settings and in three different modes.",2]
  25.    SH[50,70,"Each time you are ready to go on to the next stage of",2]
  26.    SH[50,80,"the demo, click on the OK button in the Palette Setter.",2]
  27.    SH[60,100,"The seven settings will be :",2]
  28.    SH[80,120,"Hires : 4, 8, and 16 colours",3]
  29.    SH[80,130,"Lores : 4, 8, 16, and 32 colours",3]
  30.    SH[50,150,"The demo contains brief explanations.",2]
  31.    SH[50,160,"Those on the first screen are largely unnecessary,",2]
  32.    SH[50,170,"but the later ones will be more informative.",2]
  33.    SH[180,190,"Press any key to start",3]
  34.    Wait Key 
  35. End Proc
  36. Procedure LUPE[N,W,RES]
  37.    For S=1 To N
  38.       NC=2^(S+1)
  39.       Screen Open 1,W,260,NC,RES : Colour 1,$79A
  40.       Curs Off : Flash Off 
  41.       If W=640
  42.          On S Proc EX1,EX2,EX3
  43.       End If 
  44.       'Set the mode
  45.       F$="0"
  46.       If W=320
  47.          If S=3 : F$="1" : End If 
  48.          If S=4
  49.             If Exist(":Amospic.IFF")
  50.                F$=":Amospic.IFF"
  51.             Else 
  52.                Locate 7,15 : Print ":Amospic.IFF not found"
  53.             End If 
  54.          End If 
  55.       End If 
  56.       PALET[F$]
  57.       Screen Close 1
  58.    Next 
  59. End Proc
  60. Procedure EX1
  61.    Ink 2
  62.    Polyline 116,102 To 116,106 To 210,106 To 210,102
  63.    Draw 162,106 To 162,114
  64.    SH[130,124,"Click on",2] : SH[130,132,"these to",2]
  65.    SH[130,140,"select a",2] : SH[130,148,"colour.",2]
  66.    Polyline 306,22 To 314,22 To 314,52 To 306,52
  67.    Draw 314,37 To 322,37
  68.    SH[330,36,"Click or slide on these",2]
  69.    SH[330,44,"to adjust RGB settings.",2]
  70.    SH[44,52,"$RGB -->",2] : SH[4,26,"Current",2]
  71.    SH[4,36,"selection -->",2]
  72.    SH[250,150,"Click on 'OK' when ready.",3]
  73. End Proc
  74. Procedure EX2
  75.    SH[320,20,"Copy, Swap, and Range",3]
  76.    SH[330,30,"Click on the 'From' colour,",2]
  77.    SH[330,38,"then on 'Copy', 'Swap' or 'Range',",2]
  78.    SH[330,46,"and then on the 'To/With' colour.",2]
  79.    SH[320,58,"OK",3]
  80.    SH[330,68,"Closes the Palette Setter.",2]
  81.    SH[320,80,"Save",3]
  82.    SH[330,90,"Stores current RGB settings in",2]
  83.    SH[330,98,"'RAM:palset.ASC', for future use.",2]
  84.    SH[320,110,"Fix",3]
  85.    SH[330,120,"Makes current settings the",2]
  86.    SH[330,128,"base for future resets.",2]
  87.    SH[320,140,"Rset",3]
  88.    SH[330,150,"Resets all colours.  Resets to the",2]
  89.    SH[330,158,"'Fixed' set if Fix has been used.",2]
  90.    SH[60,168,"MOVING THE SETTER",3]
  91.    SH[80,178,"To move the Palette Setter, press the Left Mouse",2]
  92.    SH[80,186,"Button in the Sample Colour box (top left).",2]
  93.    SH[80,194,"Drag a flickering rectangle the size of the Palette",2]
  94.    SH[80,202,"Setter to its new position.  Click it into place.",2]
  95.    SH[80,210,"It will remain within screen boundaries.",2]
  96. End Proc
  97. Procedure EX3
  98.    SH[320,20,"To include the Palette Setter",2]
  99.    SH[320,30,"in another AMOS program,",2]
  100.    SH[320,40,"copy the procedures used in this",2]
  101.    SH[320,50,"demo, from 'Procedure PALET[mode$]'",2]
  102.    SH[320,60,"to 'Procedure NEWPOS' inclusive.",2]
  103.    SH[320,80,"Invoke them with the call",2]
  104.    SH[320,90,"'PALET[mode$]', activated by a",2]
  105.    SH[320,100,"gadget, key press, or whatever.",2]
  106.    SH[10,110,"MODES",3]
  107.    SH[30,120,"The string argument in PALET[mode$] has three settings.",2]
  108.    SH[40,130,'- PALET["0"] runs the Palette Setter on the current screen.',2]
  109.    SH[40,140,'- PALET["1"] opens a file selector.  A selected IFF file will appear on',2]
  110.    SH[56,148,"a screen of appropriate dimensions, with the Palette Setter on top.",2]
  111.    SH[40,158,'- PALET[pic$] automatically loads the IFF file "pic$"',2]
  112.    SH[56,166,"(if it exists) before the Palette Setter appears.",2]
  113.    SH[10,178,"COLOURS",3]
  114.    SH[30,188,'The ["0"] mode starts off with the colours as set in P$ in the',2]
  115.    SH[30,196,"PALET[mode$] procedure, and the Rset gadget resets everything",2]
  116.    SH[30,204,"to those colours unless Fix has subsequently been used.",2]
  117.    SH[30,212,'The "Save" gadget makes it easy to make a new base set if you wish to.',2]
  118.    SH[30,226,"The other two modes open with the colours of the loaded file, but",2]
  119.    SH[30,234,"unless you use the Fix gadget, the Rset gadget will reset them",2]
  120.    SH[30,242,"to those defined in P$.",2]
  121. End Proc
  122. Procedure EX4
  123.    Screen Open 1,640,260,4,Hires : RESET
  124.    Curs Off : Flash Off 
  125.    SH[44,40,"Four demo screens in Lowres (Width = 320).",3]
  126.    SH[60,60,"These will use 4, 8, 16, and 32 colours.",2]
  127.    SH[60,70,"The third of the four is set to display a file selector.",2]
  128.    SH[60,80,"Just click on Quit for now.",2]
  129.    SH[60,110,"For the last example, the file :Amospic.IFF will be",2]
  130.    SH[60,120,"loaded, and the colours of that file will be used.",2]
  131.    SH[60,130,"If you encounter a problem, check its location.",2]
  132.    SH[60,150,"A click on Fix will prevent the colours on the screen from",2]
  133.    SH[60,160,"being Reset to the Palette Setter's own set of colours.",2]
  134.    SH[140,180,"Press any key to continue.",3]
  135.    Wait Key : Screen Close 1
  136. End Proc
  137. Procedure SH[TX,TY,T$,I]
  138.    Colour 3,$FB5
  139.    Gr Writing 0
  140.    Ink 0 : Text TX+1,TY+1,T$
  141.    Ink I : Text TX,TY,T$
  142. End Proc
  143. ' =============  Procedures called by PALET[mode$]  =============
  144. Procedure PALET[F$]
  145.    If F$="1"
  146.       F$=Fsel$("*.IFF","","Load an IFF file") : 
  147.       If F$<>"" : Load Iff F$,1 : End If 
  148.    Else 
  149.       If F$<>"0" : Load Iff F$ : End If 
  150.    End If 
  151.    Shared WX,WY,P$
  152.    SW=Screen Width
  153.    NC=Screen Colour
  154.    P$="$000,$79A,$FFF,$FB5,$FF0,$0F0,$F00,$800,$9DF,$59F,$D00,$ACC,$FC0,$D80,$840,$FCC,$FFF,$DDD,$CCC,$AAA,$999,$777,$666,$444,$FB0,$EA0,$C90,$B80,$A60,$950,$740,$630"
  155.    Reserve Zone NC+10 : Flash Off : Curs Off 
  156.    WX=SW/4-50 : WY=20
  157.    Wind Save 
  158.    If(F$="0") or(F$="") : RESET : End If 
  159.    Repeat 
  160.       PALWIN
  161.    Until Param=0
  162. End Proc
  163. Procedure PALWIN
  164.    Shared WX,WY,CHOYCE
  165.    OPEN_WINDOW[1] : Curs Off 
  166.    PREPARE_SAMPLER
  167.    CHOYCE=1 : H$=Hex$(Colour(1),3) : DISPLAY_H : SLIDER_VALUES : PZ=0
  168.    MAIN
  169.    AGAIN=(Param=10)
  170.    Wind Close 
  171. End Proc[AGAIN]
  172. Procedure MAIN
  173.    Shared WX,WY,X,Z,CHOYCE,P$
  174.    NC=Screen Colour
  175.    Limit Mouse 128,42 To 446,298
  176.    Repeat 
  177.       M=Mouse Key : Z=Mouse Zone
  178.       If Z<4 : SLIDER[Z]
  179.       Else 
  180.          If Z>3 and Z<11 and M
  181.             X=X Mouse : X=X Screen(X)
  182.             On Z-3 Proc DUP_COL,RANGE,QUIT,SAIVE,FIKS,RESET,NEWPOS
  183.          Else 
  184.             If(Z>10) and(Z<(NC+11)) and M : CHOOSE_COLOUR : M=0 : End If 
  185.          End If 
  186.       End If 
  187.    Until M<>0 and(Z=6 or Z=(10))
  188. End Proc[Z]
  189. Procedure FIKS
  190.    Shared P$
  191.    W_SH[114,75,"Fix",2]
  192.    NC=Screen Colour
  193.    P$=""
  194.    For I=0 To NC-1
  195.       P$=P$+Hex$(Colour(I),3)+","
  196.    Next 
  197.    W_SH[114,75,"Fix",3]
  198. End Proc
  199. Procedure RESET
  200.    Shared P$
  201.    NC=Screen Colour
  202.    For I=0 To NC-1
  203.       C$=(Mid$(P$,(I*5)+1,4)) : Colour I,Val(C$)
  204.    Next 
  205. End Proc
  206. Procedure QUIT
  207. End Proc
  208. Procedure SAIVE
  209.    Shared WX,WY,P$
  210.    W_SH[150,64,"Save",2]
  211.    Open Out 1,"RAM:palset.ASC"
  212.    Print #1,""
  213.    Print #1,"     The characters between < and > may be assigned to P$"
  214.    Print #1,"     in the 11th line of Procedure PALET[].  For this, there"
  215.    Print #1,"     must be FOUR characters in each element (e.g. $F00"
  216.    Print #1,"     should not be reduced to $F)."
  217.    Print #1,""
  218.    Print #1,"<"
  219.    Print #1,P$
  220.    Print #1,">"
  221.    Print #1,""
  222.    Print #1,"     The data may, of course, be useful in other applications."
  223.    Close 1
  224.    W_SH[150,64,"Save",3]
  225. End Proc
  226. Procedure DUP_COL
  227.    Shared WX,WY,CHOYCE,X
  228.    D1=Val(Hex$(Colour(CHOYCE),3))
  229.    Gr Writing 0
  230.    If X<WX+146
  231.       MBOSS[110,35,145,44] : W_SH[113,42,"To?",2]
  232.    Else 
  233.       MBOSS[148,35,184,44] : W_SH[151,42,"With",2]
  234.    End If 
  235.    NEWZ=0 : Repeat : M=Mouse Click : NEWZ=Mouse Zone : Until NEWZ>10 and M
  236.    D2=Val(Hex$(Colour(NEWZ-11),3))
  237.    Colour NEWZ-11,D1
  238.    If X<WX+146
  239.       MBOSS[110,35,145,44] : W_SH[113,42,"Copy",3]
  240.    Else 
  241.       Colour CHOYCE,D2
  242.       MBOSS[148,35,184,44] : W_SH[151,42,"Swap",3] : 
  243.    End If 
  244.    Gr Writing 1
  245. End Proc
  246. Procedure RANGE
  247.    Shared WX,WY,CHOYCE
  248.    W_SH[158,53,"To?",2]
  249.    Repeat : M=Mouse Click : NEWZ=Mouse Zone : Until NEWZ>10 and M
  250.    Ink 1 : W_BAR[158,47,182,54] : FIRST=CHOYCE : LAST=NEWZ-11
  251.    C1$=Hex$(Colour(FIRST),3)
  252.    R1=Val(Left$(C1$,2)) : G1=Val("$"+Mid$(C1$,3,1))
  253.    B1=Val("$"+Right$(C1$,1))
  254.    C2$=Hex$(Colour(LAST),3)
  255.    R2=Val(Left$(C2$,2)) : G2=Val("$"+Mid$(C2$,3,1))
  256.    B2=Val("$"+Right$(C2$,1))
  257.    CASES#=Abs(LAST-FIRST) : If LAST=FIRST : Pop Proc : End If 
  258.    RDIR=(R1>R2)+Abs(R1<R2) : GDIR=(G1>G2)+Abs(G1<G2)
  259.    BDIR=(B1>B2)+Abs(B1<B2)
  260.    RDIST#=Abs(R1-R2) : R_PIECE#=(RDIST#/CASES#)
  261.    GDIST#=Abs(G1-G2) : G_PIECE#=(GDIST#/CASES#)
  262.    BDIST#=Abs(B1-B2) : B_PIECE#=(BDIST#/CASES#) : T=0
  263.    For K=FIRST+1 To LAST-1
  264.       Inc T
  265.       NEWR#=R1+RDIR*T*R_PIECE# : NEWG#=G1+GDIR*T*G_PIECE#
  266.       NEWB#=B1+BDIR*T*B_PIECE#
  267.       THISCOL=Val(Hex$(Int(NEWR#+0.5),1)+Right$(Hex$(Int(NEWG#+0.5),1),1)+Right$(Hex$(Int(NEWB#+0.5),1),1))
  268.       Colour K,THISCOL
  269.    Next 
  270. End Proc
  271. Procedure CHOOSE_COLOUR
  272.    Shared WX,WY,Z,CHOYCE,H$
  273.    CHOYCE=Z-11
  274.    DISPLAY_H
  275.    Colour CHOYCE,Val(H$)
  276.    Ink CHOYCE : W_BAR[7,3,35,20]
  277.    SLIDER_VALUES
  278. End Proc
  279. Procedure DISPLAY_H
  280.    Shared WX,WY,CHOYCE,H$
  281.    H$=Hex$(Colour(CHOYCE),3)
  282.    Gr Writing 1 : Ink 0,1 : Text WX+9,WY+31,Right$(H$,3) : Ink 2,1
  283. End Proc
  284. Procedure PREPARE_SAMPLER
  285.    Shared WX,WY
  286.    MBOSS[6,2,36,21] : MBOSS[6,23,36,33]
  287.    W_ZONE[10,6,2,36,21]
  288.    W_SH[44,9,"R",3] : W_SH[44,19,"G",3]
  289.    W_SH[44,29,"B",3]
  290.    X1=56 : X2=184
  291.    For I=0 To 2
  292.       Y1=2+I*10 : Y2=10+I*10 : MBOSS[X1,Y1,X2,Y2]
  293.       W_ZONE[I+1,X1,Y1,X2,Y2]
  294.       If I<2
  295.          Ink 0 : For J=1 To 15 : W_PLOT[WX,WY,X1+J*8,Y2+1] : Next 
  296.       End If 
  297.    Next 
  298.    MBOSS[110,35,145,44] : MBOSS[148,35,184,44] : W_ZONE[4,110,35,184,44]
  299.    MBOSS[110,46,184,55] : W_ZONE[5,110,46,184,55]
  300.    MBOSS[110,57,145,66] : W_ZONE[6,110,57,145,66]
  301.    MBOSS[148,57,184,66] : W_ZONE[7,148,57,184,66]
  302.    MBOSS[110,68,145,77] : W_ZONE[8,110,68,145,77]
  303.    MBOSS[148,68,184,77] : W_ZONE[9,148,68,184,77]
  304.    W_SH[113,42,"Copy",3] : W_SH[151,42,"Swap",3] : W_SH[114,53,"Range",3]
  305.    W_SH[114,64,"OK",3] : W_SH[151,64,"Save",3]
  306.    W_SH[114,75,"Fix",3] : W_SH[151,75,"Rset",3]
  307.    '  Sample rows 
  308.    X1=6 : Y1=36 : X2=102 : Y2=76
  309.    NC=Screen Colour
  310.    MBOSS[X1-1,Y1,X2,Y2+1]
  311.    NROWS=2+2*Abs(NC>12) : NCOLS=NC/(2+(2*Abs(NC>8)))
  312.    RSTEP=40/NROWS : CSTEP=96/NCOLS
  313.    R1=Y1 : C1=X1 : C2=X2-CSTEP : I=0
  314.    For R=1 To NROWS
  315.       For C=1 To NCOLS
  316.          Ink I : W_BAR[C1,R1+1,C1+CSTEP-1,R1+RSTEP]
  317.          W_ZONE[I+11,C1+1,R1+1,C1+CSTEP-1,R1+RSTEP]
  318.          Add C1,CSTEP,X1 To C2 : Inc I
  319.       Next 
  320.       Add R1,RSTEP
  321.    Next 
  322. End Proc
  323. Procedure OPEN_WINDOW[N]
  324.    Shared WX,WY
  325.    WX=(WX+8)/16*16
  326.    Wind Open N,WX,WY,24,10 : Curs Off : Flash Off 
  327.    Ink 2 : Set Pattern 31 : W_BAR[1,1,191,79] : Set Pattern 0
  328.    X2=WX+191 : Y2=WY+79
  329.    Ink 2 : Polyline WX,Y2 To X2,Y2 To X2,WY
  330.    Ink 0 : Polyline WX,Y2 To WX,WY To X2,WY
  331. End Proc
  332. Procedure MBOSS[X1,Y1,X2,Y2]
  333.    Shared WX,WY
  334.    Add X1,WX : Add Y1,WY : Add X2,WX : Add Y2,WY
  335.    Ink 1 : Bar X1,Y1 To X2,Y2
  336.    Ink 0 : Polyline X1,Y2 To X2,Y2 To X2,Y1
  337.    Ink 2 : Polyline X1,Y2 To X1,Y1 To X2,Y1
  338. End Proc
  339. Procedure W_SH[TX,TY,T$,I]
  340.    Shared WX,WY
  341.    Gr Writing 0
  342.    Ink 0 : Text WX+TX+1,WY+TY+1,T$
  343.    Ink I : Text WX+TX,WY+TY,T$
  344.    Gr Writing 1
  345. End Proc
  346. Procedure W_PLOT[WX,WY,X,Y]
  347.    Plot WX+X,WY+Y
  348. End Proc
  349. Procedure W_DRAW[X1,Y1,X2,Y2]
  350.    Shared WX,WY
  351.    Draw WX+X1,WY+Y1 To WX+X2,WY+Y2
  352. End Proc
  353. Procedure W_BAR[X1,Y1,X2,Y2]
  354.    Shared WX,WY
  355.    Bar WX+X1,WY+Y1 To WX+X2,WY+Y2
  356. End Proc
  357. Procedure W_ZONE[N,X1,Y1,X2,Y2]
  358.    Shared WX,WY
  359.    Set Zone N,WX+X1,WY+Y1 To WX+X2,WY+Y2
  360. End Proc
  361. Procedure SLIDER[Z]
  362.    Shared WX,WY,Z,CHOYCE,H$
  363.    PX=0
  364.    While Mouse Key=1
  365.       X=X Screen(X Mouse)
  366.       If Z>0 and X<>PX and X>WX+56
  367.          DISPLAY_H
  368.          RED$="$"+Mid$(H$,2,1) : GREEN$="$"+Mid$(H$,3,1)
  369.          BLUE$="$"+Right$(H$,1)
  370.          X1=WX+57 : X2=X : X3=X1+126 : Y1=WY+3+(Z-1)*10 : Y2=Y1+6
  371.          If X1+1<X2 and X2<X3 : 
  372.             Ink 2 : Set Pattern 32 : Bar X1+1,Y1+1 To X2,Y2-1
  373.             Set Pattern 0
  374.             If X2+1<X3 : Ink 1 : Bar X2,Y1 To X3,Y2 : End If 
  375.             'Set colour as bar moves 
  376.             DISTANCE=(X2-X1)/8
  377.             If DISTANCE<10
  378.                DIST$=Str$(DISTANCE)
  379.             Else 
  380.                DIST$=Chr$(55+DISTANCE)
  381.             End If 
  382.             If Z=1 : RED$=DIST$
  383.             Else 
  384.                If Z=2 : GREEN$=DIST$
  385.                Else 
  386.                   If Z=3 : BLUE$=DIST$ : End If 
  387.                End If 
  388.             End If 
  389.             H$="$"+Right$(RED$,1)+Right$(GREEN$,1)+Right$(BLUE$,1)
  390.             Colour CHOYCE,Val("$"+Right$(RED$,1)+Right$(GREEN$,1)+Right$(BLUE$,1))
  391.             Ink CHOYCE : Bar WX+7,WY+3 To WX+35,WY+17 : DISPLAY_H
  392.          End If 
  393.       End If 
  394.       PX=X
  395.    Wend 
  396. End Proc
  397. Procedure SLIDER_VALUES
  398.    Shared WX,WY,H$
  399.    RED$="$"+Mid$(H$,2,1) : GREEN$="$"+Mid$(H$,3,1) : BLUE$="$"+Right$(H$,1)
  400.    X1=WX+57 : X3=X1+126
  401.    For Z=1 To 3
  402.       If Z=1 : X2=Val(RED$)
  403.       Else 
  404.          If Z=2 : X2=Val(GREEN$)
  405.          Else 
  406.             X2=Val(BLUE$)
  407.          End If 
  408.       End If 
  409.       X2=WX+56+X2*8+8 : Y1=WY+3+(Z-1)*10 : Y2=Y1+6
  410.       Ink 2 : Set Pattern 32 : Bar X1+1,Y1+1 To X2-1,Y2-1 : Set Pattern 0
  411.       If X2+1<X3 : Ink 1 : Bar X2,Y1 To X3,Y2 : End If 
  412.    Next 
  413. End Proc
  414. Procedure NEWPOS
  415.    Shared WX,WY
  416.    SW=Screen Width
  417.    M=0 : Ink 3 : Gr Writing 2
  418.    While M=0
  419.       X=X Screen(X Mouse) : Y=Y Screen(Y Mouse)
  420.       If X<>OX and Y<>OY
  421.          Box X,Y To X+192,Y+80 : Box X,Y To X+192,Y+80
  422.       End If 
  423.       M=Mouse Click : OX=X : OY=Y
  424.    Wend 
  425.    Ink 1 : Gr Writing 1
  426.    WX=X Screen(X Mouse) : If WX>SW-192 : WX=SW-192 : End If 
  427.    WY=Y Screen(Y Mouse) : If WY>180 : WY=176 : End If 
  428.    WX=(WX+8)/16*16
  429. End Proc
  430.